import pandas as pd
from pandas import DataFrame

datafile = './文本/客运量_1-15.csv' 
datafile2 = './文本/货运量_1-15.csv'
datafile3 = './文本/客运量_1-16.csv' 
datafile4 = './文本/货运量_1-16.csv'

data = pd.DataFrame(pd.read_csv(datafile))
data2 = pd.DataFrame(pd.read_csv(datafile2))

#客运量 
data = data.sort_values(by=['Year'],ascending=True) #重排序
name = data[data['Year'] == 2010]['Airport name'].tolist() #将机场名存到一个列表里
li = []
for i in range(len(name)):
    l = (data[data['Airport name'] == name[i]]['Whole year']).tolist()
    li.append(l) #将对应的Whole year值存到列表里
data3 = pd.DataFrame(li,columns = ['2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019']) #新建Dataframe
data3.insert(0,u'机场名',name) #将机场名作为第0列
data3.to_csv(datafile3,index=False,encoding='utf_8_sig')

#货运量
data2 = data2.sort_values(by=['Year'],ascending=True)
name2 = data2[data2['Year'] == 2010]['Airport name'].tolist()
li2 = []
for i in range(len(name2)):
    l2 = (data2[data2['Airport name'] == name2[i]]['Whole year']).tolist()
    li2.append(l2)
data4 = pd.DataFrame(li2,columns = ['2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019'])
data4.insert(0,u'机场名',name2)
data4.to_csv(datafile4,index=False,encoding='utf_8_sig')